package solution._0090._0098;

import common.TreeNode;

/**
 * Created by chen_snow
 * Date: 2021/7/3 16:30
 * Description: 验证二叉搜索树
 */
public class Solution {
    public boolean isValidBST(TreeNode root) {
        return isValid(root, null, null);
    }

    public boolean isValid(TreeNode root, TreeNode min, TreeNode max) {
        if (root == null) {
            return true;
        }

        if (min != null && root.val <= min.val){
            return false;
        }

        if (max != null && root.val >= max.val){
            return false;
        }

        return isValid(root.left, min, root) && isValid(root.right, root, max);
    }
}
